<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/treetable/jquery.treetable.css" />
    <link rel="stylesheet" href="/css/treetable/jquery.treetable.theme.default.css" />
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-select.min.css">
    <script src="/js/libs/jquery-2.1.1.min.js"></script>
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script src="/js/bootstrap/bootstrap-select.min.js"></script>
    <script src="/js/jq.js"></script>
    <script src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/layui/layui.js"></script>
    <script src="/js/dict.js"></script>
    <script src="/js/libs/jquery.ztree.all-3.5.min.js"></script>
    <script src="/js/my/ztree-menu.js"></script>
    <script src="/js/my/permission.js"></script>
    <script src="/js/plugin/datatables/jquery.dataTables.min.js"></script>
    <script src="/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
    <script src="/js/libs/jquery.treetable.js"></script>
</head>
<body>
<div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div>
            <header style="height: 100%">
                <div align="left">
                    <table style="width: 100%">
                        <tr>
                            <td>
                                <form id="form" class="form-inline" method="post" action="/stock/export" enctype="multipart/form-data">
                                    <div class="form-group">
                                        <input id="type" name="type" type="hidden" class="form-control" value="admin">
                                        商品编码:
                                        <input id="goodsCode" name="goodsCode" type="text" class="form-control" placeholder="商品编码">

                                        商品名称:
                                        <input id="goodsName" name="goodsName" type="text" class="form-control" placeholder="商品名称">
                                        分类：
                                        <input class='form-control' type='hidden' name='category' id='category' >
                                        <input  class='form-control' placeholder='商品类型' type='text' name='categoryName' id='categoryName' readonly>
                                        <a class="layui-btn layui-btn-sm" href="#"
                                                onclick="showTree('category', 'categoryName', 'goodsCategory', '商品类型', 'root', 'select');return false;">
                                            <i class="layui-icon">&#xe615;</i>
                                        </a>
                                        所属公司：
                                        <select class="form-control" name="companyId" id="companyId"
                                                title="所属公司" data-live-search="true">
                                            <option value="" selected>--请选择--</option>
                                        </select>

                                    </div>
                                </form>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <button id="searchBt" class="layui-btn layui-btn-sm search"><i class="layui-icon" permission="fas:stockD:query">&#xe615;</i>搜索</button>
                            </td>
                            <td align="right">
                                <iframe id="export" style="display:none"></iframe>
                                <button class='layui-btn layui-btn-sm' permission="fas:stockP:export" onclick="exportData()">
                                    <i class='layui-icon'>&#xe601;</i> 导出
                                </button>
                            </td>
                        </tr>
                    </table>
                </div>
            </header>

            <div>
                <div class="widget-body no-padding">
                    <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                        <thead>
                            <tr>
                            </tr>
                            <tr>
                                <th>id</th>
								<th>商品编码</th>
								<th>商品名称</th>
                                <th>商品分类</th>
								<th>所属部门</th>
								<th>所属公司</th>
								<th>总数量</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
    <script type="text/javascript">
    var pers = checkPermission();

    $(function () {
        showDictSelect('companyId', 'company', '--请选择--');
    })

var example;
function init(){
	example = 
    	$('#dt-table').DataTable({
        	"searching": false,
        	"processing": false,
        	"serverSide" : true,
        	"language": {
                "url": "/js/plugin/datatables/Chinese.lang"
            },
        	"ajax": {
        		"url" : "/stock/list",
        		"type":"get",
        		"data":function(d){
    				d.goodsCode=$('#goodsCode').val();
                    d.goodsName=$('#goodsName').val();
                    d.category=$('#category').val();
                    d.userId=$('#userId').val();
                    d.deptId=$('#deptId').val();
                    d.companyId=$('#companyId').val();
                    d.type='dept';
                    d.dept='admin';
    			}
        	},
        	"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",	
            "columns": [
                {"data" : "id", "defaultContent" : "", "visible": false},
				{"data" : "goodsCode", "defaultContent" : ""},
				{"data" : "goodsName", "defaultContent" : ""},
				{"data" : "categoryName", "defaultContent" : ""},
				{"data" : "deptName", "defaultContent" : ""},
				{"data" : "companyName", "defaultContent" : ""},
				{"data" : "totalNumber1", "defaultContent" : ""},
                ],
            "order": [[ 0, "asc" ]],
            "createdRow": function ( row, data, index ) {
                $(row).bind({
                    click: function () {
                        if ($(this).hasClass('success') ) {
                            $(this).removeClass('success');
                        } else {
                            example.$('tr.success').removeClass('success');
                            $(this).addClass('success');
                        }
                    },
                    dblclick: function () {
                        if ($.inArray("fas:stockAdmin:edit", pers) >= 0) {
                            var id = data.id;
                            openIFrame("updateStock.html?id=" + id);
                        }
                    }
                });
            }
        } );
}



layui.use('layer', function(){
    var layer = layui.layer;
});



$("#searchBt").click(function(){
	example.ajax.reload();
});

init();

// 导出
function exportData() {
    $('#form').attr('action', '/stock/export/1').submit();
}

</script>
